// src/fanyi.js
const { db } = require('./db')
const { callBaidu } = require('./call-baidu')

/**
 * This is the top level method
 * @param {string} content
 * @param {string} from
 * @param {string} to
 */
function fanyi(content, from="en", to="zh") {
  return db(content)
    .then(id => (
      callBaidu(content, from, to)
        .then(result => db(content, id, result)
      )
    ))
}

module.exports = { fanyi }
